<?php
Yii::app()->clientScript->registerScriptFile('js/highcharts.js', CClientScript::POS_END);
Yii::app()->clientScript->registerScriptFile('js/exporting.js', CClientScript::POS_END);
?>
<div style="width:100%;overflow-x:auto;">
<div id="container" style="width:<?php echo  count($data)*2*20?>px;height:240px;margin:0 auto;"></div>

<script>


$(function () {
    var chart;
    $(document).ready(function() {
    
        var colors = Highcharts.getOptions().colors,
            categories = [ 
                          <?php $col =1; foreach ($data as $val){
	                           echo "'".$col."'".', '; 
                               $col ++;     
                          } ?>
                          ],
            name = '电池编号',
            data = [
                  
            	<?php foreach ($data as $val){
            	$col = $val["STATUS_N"] == 0  ?  "\"#006400\"" : ( $val["STATUS_N"] == 1 ?  "\"#CDCD00\"" :   "\"#CD0000\"" )  ;
            	//$col = "\"#006400\"";
            	echo "{ " ;
            	echo "y: ".$val["CURINNER_N"].',  ' ; 
            	//echo '<br>';
            	echo "color: ".$col.", ";
          		echo  "}, " ;
          		
            	} ?>  ];
    
        function setChart(name, categories, data, color) {
			chart.xAxis[0].setCategories(categories, false);
			chart.series[0].remove(false);
			chart.addSeries({
				name: name,
				data: data,
				color: color 
			}, false);
			chart.redraw();
        }
    
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                type: 'column'
            },
            title: {
                text: '电池电压和电池内阻对比图'
            },
            subtitle: {
                text: ''
            },
            xAxis: {
                categories: categories
            },
            yAxis: {
                title: {
                    text: '电池内阻'
                }
            },
            plotOptions: {
                column: {
                    cursor: 'pointer',
                    point: {
                        events: {
                            click: function() {
                                var drilldown = this.drilldown;
                                if (drilldown) { // drill down
                                    setChart(drilldown.name, drilldown.categories, drilldown.data, drilldown.color);
                                } else { // restore
                                    setChart(name, categories, data);
                                }
                            }
                        }
                    },
                    dataLabels: {
                        enabled: true,
                        color: colors[0],
                        style: {
                            fontWeight: 'bold'
                        },
                        formatter: function() {
                            return ;//this.y  ;
                        }
                    }
                }
            },
            tooltip: {
                formatter: function() {
                    var point = this.point,
                        s = '电池编号：' + this.x +'，<b>'+ ' 电池内阻' +　this.y +' </b><br/>';
                    if (point.drilldown) {
                        s += 'Click to view '+ point.category +' versions';
                    } else {
                        s += '';
                    }
                    return s;
                }
            },
            series: [{
                name: name,
                data: data,
                color: 'white'
            }],
            exporting: {
                enabled: false
            }
        });
    });
    
});



</script>




<div id="container1" style="width:<?php echo count($data)*2*20?>px;height:240px;margin:0 auto;"></div>
</div>
<script>


$(function () {
    var chart;
    $(document).ready(function() {
    
        var colors = Highcharts.getOptions().colors,
            categories = [ 
                          <?php $col=1; foreach ($data as $val){
                              //echo "'".$val["record_id"]."'".', '; 
                              echo "'".$col."'".', ';
                              $col ++;
                          } ?>
                          ],
            name = '电池编号',
            data = [
                  
            	<?php foreach ($data as $val){
            	//$col = $val["STATUS_N"] == 0  ?  "\"#006400\"" : ( $val["STATUS_N"] == 1 ?  "\"#CDCD00\"" :   "\"#CD0000\"" )  ;
            	$col = "\"#006400\"";
            	echo "{ " ;
            	echo "y: ".$val["CURVAL_N"].',  ' ; 
            	//echo '<br>';
            	echo "color: ".$col.", ";
          		echo  "}, " ;
          		
            	} ?>  ];
    
        function setChart(name, categories, data, color) {
			chart.xAxis[0].setCategories(categories, false);
			chart.series[0].remove(false);
			chart.addSeries({
				name: name,
				data: data,
				color: color 
			}, false);
			chart.redraw();
        }
    
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container1',
                type: 'column'
            },
            title: {
                text: ''
            },
            subtitle: {
                text: '  '
            },
            xAxis: {
                categories: categories
            },
            yAxis: {
                title: {
                    text: '电池电压'
                }
            },
            plotOptions: {
                column: {
                    cursor: 'pointer',
                    point: {
                        events: {
                            click: function() {
                                var drilldown = this.drilldown;
                                if (drilldown) { // drill down
                                    setChart(drilldown.name, drilldown.categories, drilldown.data, drilldown.color);
                                } else { // restore
                                    setChart(name, categories, data);
                                }
                            }
                        }
                    },
                    dataLabels: {
                        enabled: true,
                        color: colors[0],
                        style: {
                            fontWeight: 'bold'
                        },
                        formatter: function() {
                            return ; //this.y  ;
                        }
                    }
                }
            },
            tooltip: {
                formatter: function() {
                    var point = this.point,
                        s = '电池编号：' + this.x +'，<b>'+ ' 电池电压' + this.y +'</b><br/>';
                    if (point.drilldown) {
                        s += 'Click to view '+ point.category +' versions';
                    } else {
                        s += ' ';
                    }
                    return s;
                }
            },
            series: [{
                name: name,
                data: data,
                color: 'white'
            }],
            exporting: {
                enabled: false
            }
        });
    });
    
});



</script>